<template>
  <el-card>
    <div class="">
      <el-button type="primary" size="small" @click="visible = true"
        >添加商品类别</el-button
      >
      <el-input
        class="w-250"
        prefix-icon="el-icon-search"
        placeholder="请输入搜索的内容"
      />
    </div>

    <el-table
      :data="productCategoryTree"
      height="600"
      border
      style="width: 100%"
      row-key="id"
      lazy
      :load="load"
      :tree-props="{ hasChildren: 'has_children' }"
    >
      <el-table-column prop="id" label="编号" width="195"> </el-table-column>
      <el-table-column prop="name" label="类别名称" width="195">
      </el-table-column>
      <el-table-column prop="banner_image_alt" label="类别图">
        <template v-slot="{ row }">
          <el-image
            :src="row.banner_image_alt"
            style="width: 50px; height: 50px"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="level" label="类别层级" width="195">
        <template v-slot="{ row }">
          <el-tag type="success" v-if="row.level == 0">一级分类</el-tag>
          <el-tag v-else-if="row.level == 1">二级分类</el-tag>
          <el-tag type="danger" v-else-if="row.level == 2">三级分类</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="sort_order" label="显示顺序" width="195">
      </el-table-column>
      <el-table-column label="操作" width="195"> </el-table-column>
    </el-table>

    <!-- 提供的对话框 -->
    <el-dialog title="新建商品分类" :visible.sync="visible">
      <CategoryViewEdit />
      <template v-slot:footer>
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" :loading="loading">确 定</el-button>
      </template>
    </el-dialog>
  </el-card>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import CategoryViewEdit from "./CategoryViewEdit";

export default {
  name: "CategoryView",
  components: {
    CategoryViewEdit,
  },
  data() {
    return {
      visible: false,
      loading: false,
    };
  },
  methods: {
    ...mapActions("product", ["getProductCategoryList"]),
    load(tree, treeNode, resolve) {
      // console.log(tree);
      // console.log(treeNode);
      // console.log(resolve);
      setTimeout(() => {
        resolve(tree.children);
      }, 500);
    },
  },
  computed: {
    ...mapGetters("product", ["productCategoryTree"]),
  },
  created() {
    //
    this.getProductCategoryList();
  },
};
</script>

<!-- <style lang="scss" scoped>
</style> -->
